﻿//-----------------------------------------------------------------------
// <copyright file="NewsStoryComparer.cs" company="Microsoft Corporation">
//     Copyright Microsoft Corporation. All Rights Reserved. This code released under the terms of the Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.) This is sample code only, do not use in production environments.
// </copyright>
//-----------------------------------------------------------------------

namespace Microsoft.ALMRangers.VsarTreasureMap.WindowsStoreApp.News
{
    using System;
    using System.Collections.Generic;

    /// <summary>
    /// A compared for new items that sorts based on published date.
    /// </summary>
    internal class NewsStoryComparer : IComparer<NewsStory>
    {
        /// <summary>
        /// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
        /// </summary>
        /// <param name="x">The first object to compare.</param>
        /// <param name="y">The second object to compare.</param>
        /// <returns>Value Condition Less than zero<paramref name="x" /> is less than <paramref name="y" />.Zero<paramref name="x" /> equals <paramref name="y" />.Greater than zero<paramref name="x" /> is greater than <paramref name="y" />.</returns>
        public int Compare(NewsStory x, NewsStory y)
        {
            if (x == null)
            {
                throw new ArgumentNullException("x");
            }

            if (y == null)
            {
                throw new ArgumentNullException("y");
            }

            if (x.Published > y.Published)
            {
                return -1;
            }

            if (x.Published < y.Published)
            {
                return 1;
            }

            return 0;
        }
    }
}
